﻿using Jy.Abp.GeneralTree;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace AbpProjectTemplate.Trees;

public abstract class TreeAppService : GeneralTreeAppServiceBase<Tree, Guid, TreeFilter, TreeListFilter, TreeEditDto, TreeListDto, TreeDto>
{
    protected readonly TreeType TreeType;

    public TreeAppService(
        TreeManager treeManager, 
        IRepository<Tree, Guid> treeRepository,
        TreeType treeType)
        : base(treeManager, treeRepository)
    {
        this.TreeType = treeType;
    }

    protected override Tree Map(TreeEditDto dto)
    {
        var entity = base.Map(dto);
        entity.Type = TreeType;
        return entity;
    }

    protected override void Map(TreeEditDto dto, Tree entity)
    {
        base.Map(dto, entity);
    }

    protected override async Task<IQueryable<Tree>> GetQueryAsync()
    {
        return (await base.GetQueryAsync())
                .Where(t => t.Type == TreeType);
    }

}
